package com.mallify.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mallify.common.model.product.StoreProductRelation;
import com.mallify.service.mapper.StoreProductRelationMapper;
import com.mallify.service.service.StoreProductRelationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * StoreProductRelationServiceImpl 接口实现
 * +----------------------------------------------------------------------
 * | HANSON [ HANSON赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Licensed HANSON并不是自由软件，未经许可不能去掉HANSON相关版权
 * +----------------------------------------------------------------------
 * | Author: HANSON Team <hanson0622@126.com>
 * +----------------------------------------------------------------------
 */
@Service
public class StoreProductRelationServiceImpl extends ServiceImpl<StoreProductRelationMapper, StoreProductRelation>
        implements StoreProductRelationService {

    @Resource
    private StoreProductRelationMapper storeProductRelationMapper;

    /**
     * 根据产品id和类型获取对应列表
     * @param productId 产品id
     * @param type 类型
     * @return 对应结果
     */
    @Override
    public List<StoreProductRelation> getList(Integer productId, String type) {
        LambdaQueryWrapper<StoreProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StoreProductRelation::getProductId, productId);
        lqw.eq(StoreProductRelation::getType, type);
        return storeProductRelationMapper.selectList(lqw);
    }

    /**
     * 根据商品Id取消收藏
     * @param proId 商品Id
     * @return Boolean
     */
    @Override
    public Boolean deleteByProId(Integer proId) {
        LambdaQueryWrapper<StoreProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StoreProductRelation::getProductId, proId);
        return storeProductRelationMapper.delete(lqw) > 0;
    }
}